#!/bin/bash

blade_dir=$(cd $(dirname $0) && pwd)
cd $blade_dir

echo -n "Installing vim scripts..."
mkdir -p ~/.vim/{syntax,ftdetect,indent}
ln -sf $blade_dir/vim/ftdetect/* ~/.vim/ftdetect/
ln -sf $blade_dir/vim/syntax/* ~/.vim/syntax/
ln -sf $blade_dir/vim/indent/* ~/.vim/indent/
echo ", Done."

mkdir -p ~/bin
echo -n "Installing blade auxiliary tools..."
ln -sf $blade_dir/tool/{genlibbuild,lsnobuild,lsrc,merge-static-libs,bladefunctions} ~/bin
if [ ! -f ~/.bashrc ] || ! grep "bladefunctions" ~/.bashrc 2>&1 >/dev/null; then
    echo "test -s ~/bin/bladefunctions && . ~/bin/bladefunctions || true" >> ~/.bashrc
fi
echo ", Done."

echo -n "Installing blade..."
ln -sf $blade_dir/blade ~/bin
echo ", Done."

if ! echo $PATH | grep "$HOME/bin" &> /dev/null; then
    profile=~/.bash_profile
    if echo $SHELL | grep "zsh" &> /dev/null; then
        profile=~/.zshenv
    elif [ -f ~/.profile ]; then
        profile=~/.profile
    fi
    echo 'export PATH=~/bin:$PATH' >> $profile
    echo -e "\033[1;32mInstall success, please relogin or run 'source $profile' manually to apply\033[0m"
fi

